package fr.poc.app;

import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.servlet.ServletProperties;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.FeignClientScan;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import fr.poc.rest.config.JerseyConfig;
import fr.xebia.extras.filters.logfilters.RequestLoggerFilter;

@EnableAutoConfiguration
@EnableDiscoveryClient
@ComponentScan(basePackages="fr.poc")
@FeignClientScan
public class Application {

	@Bean
	public ServletRegistrationBean jerseyServlet() {
		ServletRegistrationBean registration = new ServletRegistrationBean(
				new ServletContainer(), "/rest/*");
		registration.addInitParameter(
				ServletProperties.JAXRS_APPLICATION_CLASS,
				JerseyConfig.class.getName());
		return registration;
	}

	@Bean
	public FilterRegistrationBean requestLoggerFilter() {
		RequestLoggerFilter filter = new RequestLoggerFilter();
		FilterRegistrationBean registrationBean = new FilterRegistrationBean(
				filter, jerseyServlet());
		registrationBean.addInitParameter("maxDumpSizeInKB", "1000");
		//registrationBean.setOrder(1);

		return registrationBean;
	}

	public static void main(String[] args) throws Exception {
		new SpringApplicationBuilder(Application.class).showBanner(false).run(
				args);
	}
}